package cn.jee.repository;

import cn.jee.dto.Stu2AgeRecord;
import cn.jee.dto.Stu2NameDto;
import cn.jee.entity.Stu2;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface Stu2Repository extends JpaRepository<Stu2,Long> {
  List<Stu2> findAllByNameContainsIgnoreCase(String name);
  //名字模糊查找，age在一定范围内
  List<Stu2> searchAllByNameContainingAndAgeBetweenOrderByAgeDescIdAsc(String name,int min,int max);
  @Query("select name from Stu2")
  List<String> find2();
  @Transactional
  @Modifying
  @Query("delete from Stu2 where id<:id")
  void del(long id);

  List<Stu2> findAllByNameContainsIgnoreCase(String name, Sort sort);
  List<Stu2> findAllByNameContainsIgnoreCase(String name, Pageable pageable);
  //JPA buddy生成的查询方法
  List<Stu2> findByNameStartsWithIgnoreCaseAndAgeLessThanOrderByAgeDescIdAsc(String name, int age);
  @Query("select new cn.jee.dto.Stu2NameDto(name) from Stu2")
  List<Stu2NameDto> dto();
  @Query("select new cn.jee.dto.Stu2AgeRecord(age) from Stu2")
  List<Stu2AgeRecord> record();

}
